package cn.edu.zut.internship.service.impl.sys;

import cn.edu.zut.internship.bean.sys.Permissions;
import cn.edu.zut.internship.bean.sys.Role;
import cn.edu.zut.internship.bean.sys.SysUser;
import cn.edu.zut.internship.iservice.sys.LoginSV;
import com.alibaba.dubbo.config.annotation.Service;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

@Service
public class LoginSVImpl implements LoginSV {
    @Override
    public SysUser getUserByName(String getMapByName) {
        return getMapByName(getMapByName);
    }

    @Override
    public SysUser getMapByName(String userName) {
        //权限对象
        Permissions permissions1 = new Permissions("1", "query");
        //Permissions permissions2 = new Permissions("2", "add");
        //权限集合
        Set<Permissions> permissionsSet = new HashSet<>();
        permissionsSet.add(permissions1);
        //permissionsSet.add(permissions2);
        //角色对象
        Role role = new Role("1", "admin", permissionsSet);
        //角色集合
        Set<Long> roleSet = new HashSet<>();
        roleSet.add(1L);
        //User->Role->permissiones一个User有多个Role，一个Role有多个permission

        SysUser sysUser = new SysUser(1L, "wsl", "123456", roleSet);
        Map<String, SysUser> map = new HashMap<>();
        map.put(sysUser.getUsername(), sysUser);

        Set<Permissions> permissionsSet1 = new HashSet<>();
        permissionsSet1.add(permissions1);
        Role role1 = new Role("2", "user", permissionsSet1);
        Set<Long> roleSet1 = new HashSet<>();
        roleSet1.add(1L);
        SysUser sysUser1 = new SysUser(2L, "zhangsan", "123456", roleSet1);
        map.put(sysUser1.getUsername(), sysUser1);
        return map.get(userName);
    }
}
